import objectassign from 'object-assign'
import { REQUEST_POSTS, RECEIVE_POSTS } from './Action/Index'
import { RECEIVE_SAVE, RECEIVE_REMOVE } from './Action/Index'

const select = (state) => {
    var rtn = {};
    if (state.asyncData) {
        rtn = { type: REQUEST_POSTS, data: {}, isFetching: true };
    } else {
        if (state.fetchData) {
            if (state.fetchData.type == RECEIVE_POSTS) {
                var data = Object.assign({}, state.fetchData.data);
                rtn = Object.assign({}, state.fetchData, { pageList: data.resultList, total: data.totalCount });
            } else if (state.fetchData.type == RECEIVE_SAVE) {
                rtn = Object.assign({}, state.fetchData);
            } else if (state.fetchData.type == RECEIVE_REMOVE) {
                rtn = Object.assign({}, state.fetchData);
            }
        }
    }
    return rtn;
}

export default select;